package com.huanzhidadi.single.completablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 计算完成的后续操作 只消费，无返回
 * CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action, Executor executor)
 */
public class ThenAcceptTest {
    public static void main(String[] args) {
        System.out.println("主线程"+Thread.currentThread().getName());
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        ExecutorService executorService2 = Executors.newFixedThreadPool(10);
        CompletableFuture.supplyAsync(()->{
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("子线程"+Thread.currentThread().getName());
            return "123";
        },executorService)
                .thenAcceptAsync(value-> {
            System.out.println(value + "子线程" + Thread.currentThread().getName());
            executorService.shutdown();
            executorService2.shutdown();
        },executorService2);
        System.out.println("主线程结束"+Thread.currentThread().getName());
    }
}
